package com.example.demo.controller.aaaa;

import com.example.demo.service.aaaa.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gjy
 * @ClassName DemoController
 * @description
 * @date 2025/5/13 13:01
 */
@RestController
@RequestMapping("/demo")
public class DemoController {
    private static final Logger log = LoggerFactory.getLogger(DemoController.class);

    private final DemoService demoService;

    @Autowired
    public DemoController(DemoService demoService) {
        this.demoService = demoService;
    }

    /**
     * 查询 xml方式
     *
     * @param id
     * @return java.lang.String
     * @author gjy
     * @date 2025/5/13
     */
    @GetMapping("/{id}")
    public String getDemoById(@PathVariable Long id) {
        return demoService.getDemoById(id);
    }

    /**
     * 查询，mybatis plus 注解方式
     *
     * @param id
     * @return java.lang.String
     * @author gjy
     * @date 2025/5/13
     */
    @GetMapping("/getDemoById2")
    public String getDemoById2(@RequestParam Long id) {
        return demoService.getDemoById2(id);
    }

    @GetMapping("/search")
    public String searchDemos(@RequestParam Map<String, Object> params) {
        return demoService.searchDemos(params);
    }

    /**
     * mybatis plus 分页使用测试
     *
     * @return java.lang.String
     * @author gjy
     * @date 2025/5/15
     */
    @GetMapping("/page")
    public String page() {
        return demoService.page();
    }

    /**
     * 多数据源验证
     *
     * @return java.lang.String
     * @author gjy
     * @date 2025/5/13
     */
    @GetMapping("/dataSynchronization")
    public String dataSynchronization() {
        return demoService.dataSynchronization();
    }

    @GetMapping("/large-log")
    public String testLargeLog() {
        // 生成大日志（测试滚动）
        for (int i = 0; i < 50000 * 20; i++) {
            log.debug("Large log message to test rolling: " + i);
            log.info("Large log message to test rolling: " + i);
            log.warn("Large log message to test rolling: " + i);
            log.error("Large log message to test rolling: " + i);
        }
        return "Large log test triggered (check archive directory)";
    }
}
